package com.maistars.spider.service.parser.policy.impl;

import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.maistars.spider.service.parser.policy.ParserPolicy;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author dhr
 * @date 2021/1/17 上午1:31
 */
public class JsonPathPolicy implements ParserPolicy {

    private DocumentContext documentContext;

    @Override
    public void init(String content) {
        documentContext = JsonPath.parse(content);
    }

    @Override
    public List<String> execute(String path, Map<String, String> filterParams) {
        List<String> result = new ArrayList<>();
        result = documentContext.read(path);
        return result;
    }
}
